package org.huzhp.console.entity.vo;


import lombok.Data;
import org.huzhp.console.entity.SentinelParam;
import org.springframework.beans.BeanUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 规则类
 * @Author: huzp
 * @CreateDate: 2020/3/12 15:18
 * @Version: 1.0
 */
@Data
public class SentinelParamVo {

    private Integer paramIndex;

    private Integer paramParseStrategy;

    private String paramFieldName;

    private String paramPattern;

    private Integer paramMatchStrategy;

    public SentinelParam build() {
        if (this == null) {
            return null;
        }
        SentinelParam param = new SentinelParam();
        BeanUtils.copyProperties(this, param);
        return param;
    }


    public Object buildGatewayJson() {
        Map<String, Object> jsonMap = new HashMap<>(5);
        jsonMap.put("index", this.paramIndex);
        jsonMap.put("parseStrategy", this.paramParseStrategy);
        jsonMap.put("fieldName", this.paramFieldName);
        jsonMap.put("pattern", this.paramPattern);
        jsonMap.put("matchStrategy", this.paramMatchStrategy);
        return jsonMap;
    }

}
